(function(){
    "use strict";
    app.controller('permissionsCtrl', ['$scope', 'httpLoad', '$rootScope','$modal','$state','$timeout','LANGUAGE',
        function($scope, httpLoad, $rootScope, $modal,$state, $timeout,LANGUAGE) {
            $rootScope.moduleTitle = ' 用户中心> 权限';//定义当前页
            // $rootScope.link = '/statics/css/user.css';//引入页面样式
            $scope.param = {
                rows: 10
            };
            $scope.isbatchDelete = true;
            //获取权限列表
            $scope.getData = function(page){
                $scope.param.page = page || $scope.param.page;
                var params = {
                        page: $scope.param.page,
                        rows: $scope.param.rows,
                        authorityName: $scope.searchByAuthorityName
                    };
                   /* searchParam = [];
                if($scope.searchByRolename&&$scope.searchByRolename!=""){
                    searchParam.push({"param":{"name":$scope.searchByRolename},"sign":"LK"});
                }
                params.params = JSON.stringify(searchParam);*/
                httpLoad.loadData({
                    url:'/permissions/list',
                    method: 'POST',
                    data: params,
                    //noParam: true,
                    success:function(data){
                        if(data.rows&&data.rows.length!=0){
                            $scope.permissionsList = data.rows;
                            $scope.totalCount = data.records;
                            $scope.isImageData = false;
                        }else{
                            $scope.isImageData = true;
                        }
                    }
                });
            };
            $scope.getData(1);
            //编辑
            $scope.update = function(item){  //打开模态
                var modalInstance = $modal.open({
                    templateUrl : '/statics/tpl/userCenter/permissions/update.html',  //指向上面创建的视图
                    controller : 'updateRoleModalCtrl',// 初始化模态范围
                    resolve : {
                        itemData: function() {
                            return item;
                        }
                    }
                });
                modalInstance.result.then(function(data){
                    angular.extend(item,data);
                },function(){});
            };
        }
    ]);

    //编辑ctrl
    angular.module('app').controller('updateRoleModalCtrl',['$scope','$modalInstance','itemData','LANGUAGE','httpLoad',
        function($scope,$modalInstance,itemData,LANGUAGE,httpLoad){
            $scope.updateData = {};
            $scope.updateData.authorityName = itemData.authorityName;
            $scope.updateData.authorityDesc = itemData.authorityDesc;
            $scope.updateData.authorityRelativeUrl = itemData.authorityRelativeUrl;
            $scope.updateData.authorityType = itemData.authorityType;
            $scope.updateData.authorityRemarks = itemData.authorityRemarks;
            $scope.updateData.authorityParentId = itemData.authorityParentId;
            $scope.updateData.authorityId = itemData.authorityId;
            $scope.ok = function(){
                httpLoad.loadData({
                    url:'/permissions/updateAuthority',
                    method:'POST',
                    data: $scope.updateData,
                    success:function(data){
                        if(data.success){
                            $scope.pop(data.message);
                            $modalInstance.close($scope.updateData);
                        }
                    }
                });
            };
            $scope.cancel = function(){
                $modalInstance.dismiss('cancel'); // 退出
            };
        }]);
})();